package com.wz.project.cxtj.inOrder.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.cxtj.inOrder.domain.ViewInOrder;
import com.wz.project.cxtj.inOrder.service.IViewInOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 入库流水Controller
 * 
 * @author wz
 * @date 2022-05-19
 */
@Controller
@RequestMapping("/search/inOrder")
public class ViewInOrderController extends BaseController
{
    private String prefix = "cxtj/inOrder";

    @Autowired
    private IViewInOrderService viewInOrderService;

    @RequiresPermissions("search:inOrder:view")
    @GetMapping()
    public String inOrder()
    {
        return prefix + "/inOrder";
    }

    /**
     * 查询入库流水列表
     */
//    @RequiresPermissions("search:inOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewInOrder viewInOrder)
    {
        startPage();
        List<ViewInOrder> list = viewInOrderService.selectViewInOrderList(viewInOrder);
        return getDataTable(list);
    }

    /**
     * 导出入库流水列表
     */
//    @RequiresPermissions("search:inOrder:export")
    @Log(title = "入库流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewInOrder viewInOrder)
    {
        List<ViewInOrder> list = viewInOrderService.selectViewInOrderList(viewInOrder);
        ExcelUtil<ViewInOrder> util = new ExcelUtil<ViewInOrder>(ViewInOrder.class);
        return util.exportExcel(list, "inOrder");
    }

    /**
     * 新增入库流水
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存入库流水
     */
    @RequiresPermissions("search:inOrder:add")
    @Log(title = "入库流水", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewInOrder viewInOrder)
    {
        return toAjax(viewInOrderService.insertViewInOrder(viewInOrder));
    }

    /**
     * 修改入库流水
     */
    @GetMapping("/edit/{jobId}")
    public String edit(@PathVariable("jobId") String jobId, ModelMap mmap)
    {
        ViewInOrder viewInOrder = viewInOrderService.selectViewInOrderById(jobId);
        mmap.put("viewInOrder", viewInOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存入库流水
     */
    @RequiresPermissions("search:inOrder:edit")
    @Log(title = "入库流水", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewInOrder viewInOrder)
    {
        return toAjax(viewInOrderService.updateViewInOrder(viewInOrder));
    }

    /**
     * 删除入库流水
     */
    @RequiresPermissions("search:inOrder:remove")
    @Log(title = "入库流水", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewInOrderService.deleteViewInOrderByIds(ids));
    }
}
